import akshare as ak
import pandas as pd

# ak.fund_net_value_em(fund='010115', indicator='单位净值走势')

# data = ak.fund_open_fund_info_em(symbol='010115',indicator='单位净值走势')
# print(data)

import akshare as ak
import pandas as pd


def get_zhongzheng_baijiu():
    """专查中证白酒(161725)最新净值（不存文件）"""
    try:
        df = ak.fund_open_fund_info_em(symbol="010115", indicator="单位净值走势")
        print(df)

        # 提取关键字段并格式化
        latest = df.iloc[-1]  # 取最后一条（最新数据）
        return {
            "基金名称": "",
            "基金代码": "161725",
            "净值日期": pd.to_datetime(latest["净值日期"]).strftime('%Y-%m-%d'),
            "单位净值": float(latest["单位净值"]),
            "日涨幅": latest.get("日增长率", "N/A")
        }
    except Exception as e:
        return {"error": f"查询失败: {str(e)} (建议执行升级: pip install --upgrade akshare)"}


if __name__ == "__main__":
    # 极速查询
    result = get_zhongzheng_baijiu()

    # 清晰打印结果
    print("\n最新净值")
    print("─" * 40)
    for k, v in result.items():
        print(f"{k:>8}: {v}")
    print("─" * 40)
    print("注：数据来自AKShare实时接口，延迟约15分钟")

